home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7420 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news.uni-stuttgart.de!schweikh
  2. From: schweikh@itosun.ito.uni-stuttgart.de (Jens Schweikhardt)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: hex to dec function?
  5. Date: 26 Feb 1996 13:15:50 GMT
  6. Organization: Comp.Center (RUS), U of Stuttgart, FRG
  7. Message-ID: <4gsbq6$2dce@info4.rus.uni-stuttgart.de>
  8. References: <4gdh1b$bg@mailhost.mwmicro.com> <larry_kearney-2302960806460001@amaryllisp1.appsig.com>
  9. NNTP-Posting-Host: itosun.ito.uni-stuttgart.de
  10.  
  11. In article <larry_kearney-2302960806460001@amaryllisp1.appsig.com>,
  12. Larry Kearney <larry_kearney@appsig.com> wrote:
  13. >In article <4gdh1b$bg@mailhost.mwmicro.com>, aschlies@citynet.net wrote:
  14. >> Hi There,
  15. >> Is there a function that converts HEX to Dec in ANSI C?
  16. >> Why re-invent the wheel?
  17. >> Thanks Tony
  18. >
  19. >I assume you mean convert a character string containing hex digits
  20. >('A'-'F','0'-'9') into a decimal integer. If so, use
  21. >   unsigned int int_value;
  22. >   unsigned long int long_int_value;
  23. >   char *string_buffer;
  24. >   ...
  25.  
  26. I hope the ... means 'have a string_buffer = malloc (somesize);' here.
  27. And don't forget to put your hex string there.
  28.  
  29. >   sscanf( string_buffer, "%x", int_value );
  30. >   sscanf( string_buffer, "%lx", long_int_value );
  31.  
  32. At the risk of stating the obvious, my workstation will probably
  33. dump core because sscanf wants _pointers_ to int_value and
  34. long_int_value, i.e. &int_value.
  35. Please please please _test_compile_ any answers you give before posting.
  36. And run them. Even more so, don't post bogus code.
  37.  
  38. Thanks for your cooperation.
  39.  
  40. Bye, Jens
  41. -- 
  42. SIGSIG -- signature too long (core dumped)
  43.